/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package onpu_dms_xls.kernel.common.inputParameters;


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import onpu_dms_xls.exceptions.MyException;
import onpu_dms_xls.exceptions.MySQLException;
import onpu_dms_xls.exceptions.MyXMLException;
import onpu_dms_xls.kernel.common.XML_Parsers.SAX_XML_2DB_InputParam_Parser;
import onpu_dms_xls.kernel.common.XML_Parsers.SAX_XML_FromDB_InputParam_Parser;
import onpu_dms_xls.kernel.common.logAndDebug.Debug;
import org.xml.sax.SAXException;

/**
 *
 * @author snbm
 */
public class ToDB_InputParameters extends InputParameters{

    private int documentClassId;
    private String temporaryFolder;

    public ToDB_InputParameters (String xml, String tempFolder) throws IOException, MyException{

        File temp = new File (tempFolder +"/"+"dms_toDB_Input_temp.xml");
        if (temp.canRead()){
            temp.delete();
        }
        //xml 2 file
        FileOutputStream fos = new FileOutputStream(temp);
        fos.write(xml.getBytes());
        fos.close();

        //parseFile
        SAX_XML_2DB_InputParam_Parser sipp = new SAX_XML_2DB_InputParam_Parser();
        try{
            sipp.runExample(temp.getAbsolutePath(), this);
        } catch (IOException e){
            throw new MyXMLException(
                    "ToDB_InputParameters",
                    "ToDB_InputParameters",
                    "sipp.runExample(temp.getAbsolutePath(), this);",
                    e.getMessage()) ;
        }

        //System.out.println(this);

        //delete file
        if (temp.delete()){
            return;
        } else {
            throw new MyXMLException("ToDB_InputParameters", "ToDB_InputParameters", "error while deleting temp file", temp.getAbsolutePath());
        }
    }


    /**
     * @return the documentClassId
     */
    public int getDocumentClassId() {
        return documentClassId;
    }

    /**
     * @param documentClassId the documentClassId to set
     */
    public void setDocumentClassId(int documentClassId) {
        this.documentClassId = documentClassId;
    }




    @Override
    public String toString (){
        StringBuilder sb = new StringBuilder();
        sb.append("constParam: ").append("documentClassId: ").append(documentClassId).append("\n");

        return sb.toString();
    }

    /**
     * @return the temporaryFolder
     */
    public String getTemporaryFolder() {
        return temporaryFolder;
    }

    /**
     * @param temporaryFolder the temporaryFolder to set
     */
    public void setTemporaryFolder(String temporaryFolder) {
        this.temporaryFolder = temporaryFolder;
    }


   
}
